home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vsms111.zip / PASSWD.C < prev    next >
C/C++ Source or Header  |  1992-12-13  |  4KB  |  107 lines

  1. /*
  2.  * MX-Multiuser DOS Password Control
  3.  * Copyright (c) 1992 The MX-Multiuser DOS Project.  All rights reserved.
  4.  * chris@uuczar.dearborn.mi.us
  5.  *
  6.  * Main code for this program was written by Robert Morse
  7.  * (uunet!destroyer!medar!rmsun!rmorse)
  8.  *
  9.  * Program: PASSWD (passwd.c)
  10.  * Version: 1.0 (OS Version 1.11)
  11.  * Syntax: passwd [new-password]
  12.  *
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions
  15.  * are met:
  16.  * 1. Redistributions of source code must retain the above copyright
  17.  *    notice, this list of conditions and the following disclaimer.
  18.  * 2. Redistributions in binary form must reproduce the above copyright
  19.  *    notice, this list of conditions and the following disclaimer in the
  20.  *    documentation and/or other materials provided with the distribution.
  21.  * 3. All advertising materials mentioning features or use of this software
  22.  *    must display the following acknowledgement:
  23.  *    This product includes software developed by
  24.  *    The MX-Multiuser DOS Project and other contributors.
  25.  * 4. Neither the name of the author nor the names of its contributors
  26.  *    may be used to endorse or promote products derived from this software
  27.  *    without specific prior written permission.
  28.  *
  29.  * THIS SOFTWARE IS PROVIDED BY MX-MDOS PROJECT AND CONTRIBUTORS "AS IS" AND
  30.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE MX-MDOS PROJECT OR CONTRIBUTORS BE
  33.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36.  * INTERRUPTION)
  37.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  39.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  40.  * SUCH DAMAGE.
  41.  */
  42.  
  43. #include <stdio.h>        /* Include info needed for I/O */
  44.  
  45. char *passwd="/mxdos/mail/passwd.f";   /* Defines our password file */
  46.  
  47. /* On some DOS compilers it should be */
  48. /* char *passwd = "\\mxdos\\mail\\passwd.f"; */
  49.  
  50. /* Check if TRUE and FALSE have been defined if not define them */
  51. #ifndef TRUE
  52. #define TRUE 1
  53. #define FALSE 0
  54. #endif 
  55.  
  56. main(argc,argv)
  57. int argc;
  58. char *argv[];
  59.  
  60. {
  61.     char tpasswd[20],gpasswd[20];  /* 8 chars plus the NULL */
  62.     FILE *passwdf;
  63.     int correctp;
  64.     correctp = FALSE;
  65.  
  66.     if ( argc == 2 ) /* At burger king, what you want is what you get! */
  67.     {
  68.         if ( (passwdf = fopen(passwd,"w")) == (FILE *)NULL) /* Write err */
  69.         {
  70.             fprintf(stderr,"passwd : Error opening password file for writing\n",passwdf);
  71.             exit(0);
  72.         }
  73.         fprintf(passwdf,"%s",argv[1]);
  74.         fclose(passwdf);
  75.         printf("Password changed.\n");
  76.         exit(0);
  77.     }
  78.  
  79.     if ( argc != 1 ) /* Do they know what to do? */
  80.     {
  81.         fprintf(stderr,"Usage: passwd [new-system-password]\n");
  82.         exit(0);
  83.     }
  84.  
  85.     if ( (passwdf = fopen(passwd,"r")) == (FILE *)NULL) /* Read err */
  86.     {
  87.         fprintf(stderr,"passwd : Error opening password file for reading\n",passwdf);
  88.         exit(0);
  89.     }
  90.     
  91.     while ( !correctp )
  92.     {
  93.         fscanf(passwdf,"%20s",tpasswd); /* Get passwd from file passwdf */    
  94.         printf("\nPassword: "); /* Ask for the password */
  95.         fscanf(stdin,"%20s",gpasswd); /* Get the password from input */
  96.     
  97.         if ( strcmp( tpasswd, gpasswd) == 0) 
  98.         {
  99.             correctp = TRUE;
  100.             fclose(passwdf);
  101.             exit(1);
  102.         }
  103.  
  104.         printf("Incorrect password"); /* Sorry dude */
  105.     }
  106. }
  107.